package store.lunangangster.bpmn.converter;

import javax.xml.stream.XMLStreamReader;
import store.lunangangster.bpmn.converter.parser.ConditionExpressionParser;
import store.lunangangster.bpmn.model.BaseElement;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.SequenceFlow;
import store.lunangangster.bpmn.util.BpmnXmlUtil;

public class SequenceFlowConverter extends FlowElementConverter {

  public SequenceFlowConverter() {
    super();
    addChildElementParser(new ConditionExpressionParser());
  }

  @Override
  protected BaseElement convertToElement(XMLStreamReader xsr, BpmnModel model) throws Exception {
    SequenceFlow sequenceFlow = new SequenceFlow();

    String sourceRef = xsr.getAttributeValue(null, ATTRIBUTE_SEQUENCE_FLOW_SOURCE);
    String targetRef = xsr.getAttributeValue(null, ATTRIBUTE_SEQUENCE_FLOW_TARGET);

    sequenceFlow.setSourceRef(sourceRef);
    sequenceFlow.setTargetRef(targetRef);
    BpmnXmlUtil.addXmlLocation(xsr, sequenceFlow);

    parseChildElement(xsr,  sequenceFlow, getTargetName(), model);
    return sequenceFlow;
  }

  @Override
  public String getTargetName() {
    return ELEMENT_SEQUENCE_FLOW;
  }
}
